﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ZCSBZPJ.Filter;
using ZP.Common;
using ZP.DTO.Common;
using ZP.DTO.ep_honor_title;
using ZP.DTO.ht_honor_title;

namespace ZCSBZPJ.Controllers
{
    public class EPHonorController : BaseController
    {
        public ActionResult Index()
        {
            return View();
        }


        [AuthorityFilter]
        /// <summary>
        /// 荣誉标题-模分页模糊查询
        /// </summary>
        /// <returns></returns>
        public JsonResult GetHonorTitle(ht_honor_titleSearchDTO dto)
        {
            PageModel<ht_honor_titleResultDTO> pageList = new PageModel<ht_honor_titleResultDTO>();
            pageList = _ht_honor_titleService.GetHonorTitle(dto);
            return Json(pageList, JsonRequestBehavior.AllowGet);
        }

        [AuthorityFilter]
        public JsonResult GetAllEPHonorTitle(int? ht_type)
        {
            ResultData<List<ht_honor_titleResultDTO>> resultData = new ResultData<List<ht_honor_titleResultDTO>>();
            try
            {
                resultData.Object = _ht_honor_titleService.GetAllEPHonorTitle(ht_type);
                resultData.SubmitResult = true;
            }
            catch (Exception e)
            {
                resultData.Exception = e;
                resultData.Message = e.Message;
            }
            return Json(resultData, JsonRequestBehavior.AllowGet);
        }



        [AuthorityFilter]
        /// <summary>
        /// 保存荣誉标题-新增/修改
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public JsonResult SaveEPHonor(ht_honor_titleOperateDTO dto)
        {
            ResultData<string> result = new ResultData<string>();
            try
            {
                UserLoginDTO loginUser = (UserLoginDTO)Session[ZPCommon.SESSION_Login];
                dto.updater = loginUser.account;
                result.SubmitResult = _ht_honor_titleService.SaveEPHonor(dto);
            }
            catch (Exception e)
            {
                result.SubmitResult = false;
                result.Message = e.Message;
            }

            return Json(result);
        }

        [AuthorityFilter]
        /// <summary>
        /// 删除荣誉标题
        /// </summary>
        /// <returns></returns>
        public JsonResult DeleteEPHonor(List<ht_honor_titleOperateDTO> dto)
        {
            ResultData<string> result = new ResultData<string>();
            try
            {
                UserLoginDTO loginUser = (UserLoginDTO)Session[ZPCommon.SESSION_Login];
                result.SubmitResult = _ht_honor_titleService.DeleteEPHonor(dto, loginUser);
            }
            catch (Exception ex)
            {
                result.SubmitResult = false;
                result.Message = ex.Message;
            }
            return Json(result);
        }
    }
}